package com.u.social.sale.mq;

import com.u.social.sale.service.IOrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: awesome-spring
 * @description:
 * @author: Alex Wu
 * @createDate: 2025-02-11 13:56
 **/
@Component
@RocketMQMessageListener(topic = "%DLQ%secKill-topic-group", consumerGroup = "DLQConsumerGroup")
public class DeadLetterQueueConsumer implements RocketMQListener<String> {

    @Autowired
    private IOrderService   orderService;
    @Override
    public void onMessage(String message) {
        // 秒杀的死信队列，重试三次，还不行发人工处理，此要注意幂等性，不能重复下单
        System.out.println("DLQ received message: " + message);
        orderService.addOrderByProduct(null, null);
    }
}
